<template>
  <el-container class="admin-container">
    <!-- 头部区域 -->
    <el-header>
      <div class="header-left">
        <div class="logo">文化馆预约管理系统</div>
        <div class="subtitle">管理后台</div>
      </div>
      <div class="header-right">
        <span class="welcome">欢迎您，{{ userInfo.name }}</span>
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
            <i class="el-icon-user"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <el-menu
          :default-active="activeIndex"
          class="el-menu-vertical"
          background-color="#304156"
          text-color="#fff"
          active-text-color="#409EFF"
          router
          unique-opened
        >
          <!-- <el-menu-item index="/admin/welcome">
            <i class="el-icon-s-home"></i>
            <span slot="title">首页</span>
          </el-menu-item> -->

          <el-menu-item index="/admin/analysis">
            <i class="el-icon-data-analysis"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          
          <el-menu-item index="/admin/user">
            <i class="el-icon-user"></i>
            <span slot="title">用户管理</span>
          </el-menu-item>
          
          <el-menu-item index="/admin/exhibition">
            <i class="el-icon-picture"></i>
            <span slot="title">展览管理</span>
          </el-menu-item>
          
          <el-menu-item index="/admin/guide">
            <i class="el-icon-s-custom"></i>
            <span slot="title">解说管理</span>
          </el-menu-item>
          
          <el-menu-item index="/admin/collection">
            <i class="el-icon-collection"></i>
            <span slot="title">藏品管理</span>
          </el-menu-item>
          
          <el-menu-item index="/admin/announcement">
            <i class="el-icon-bell"></i>
            <span slot="title">公告管理</span>
          </el-menu-item>
          
          <el-menu-item index="/admin/reservation">
            <i class="el-icon-document"></i>
            <span slot="title">预约管理</span>
          </el-menu-item>
          
          <el-menu-item index="/admin/message">
            <i class="el-icon-chat-line-square"></i>
            <span slot="title">留言管理</span>
          </el-menu-item>
          
          
        </el-menu>
      </el-aside>
      
      <!-- 右侧内容区域 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'AdminHome',
  data() {
    return {
      activeIndex: '/admin/welcome'
    }
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  created() {
    // 设置当前激活的菜单项
    this.activeIndex = this.$route.path
    // 检查用户是否有管理员权限
    if (this.userInfo.role !== 'ADMIN') {
      this.$message.error('您没有管理员权限')
      this.$router.push('/home')
    }
  },
  methods: {
    // 处理下拉菜单命令
    handleCommand(command) {
      if (command === 'logout') {
        this.logout()
      }
    },
    // 退出登录
    logout() {
      this.$confirm('确认退出登录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 清除用户信息和token
        this.$store.dispatch('logout')
        // 跳转到登录页
        this.$router.push('/login')
        this.$message.success('退出登录成功')
      }).catch(() => {
        // 取消退出
      })
    }
  }
}
</script>

<style scoped>
.admin-container {
  height: 100%;
}

.el-header {
  background-color: #304156;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 16px;
  padding: 0 20px;
}

.header-left {
  display: flex;
  align-items: center;
}

.logo {
  font-size: 18px;
  font-weight: bold;
  margin-right: 10px;
}

.subtitle {
  font-size: 14px;
  background-color: #409EFF;
  padding: 2px 8px;
  border-radius: 4px;
}

.header-right {
  display: flex;
  align-items: center;
}

.welcome {
  margin-right: 15px;
}

.el-dropdown-link {
  cursor: pointer;
  color: #fff;
}

.el-aside {
  background-color: #304156;
}

.el-menu {
  border-right: none;
}

.el-menu-vertical:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
}
</style>